Would
final String charData = 3.14159265;
work?
No. charData
is an object of type String
and 3.14159265 (without the quotes around it)
is a literal of primitive type double
.
These data types use bit patterns in completely different ways.
A simple statement assigning one type to the other won't work.
In the program,
the characters "3.14159265" are contained inside
the String charData
.
final String charData = "3.14159265"; double value;
Now look at the statement
that converts the characters to a double
data type and puts the results in value
:
value = Double.parseDouble( charData ) ;
The assignment statement works in two steps:
parseDouble()
method from the class Double
examines the characters and creates a double
value.double
value is copied to
the variable value
.Usually this is called converting from character data to double precision floating point data. However, the character data is not changed. A floating point value is calculated from it and that value is copied to another location.